<script setup>
import { computed, onMounted, ref } from "vue";
import { getProjectByKw, getLateDirections } from "@/api/innovation";
import { ElMessage, FIRST_LAST_KEYS } from "element-plus";
import { SUCCESS } from "@/core/constants/HttpStatus";
import { useRouter } from "vue-router";

const teaDirectionList = ref([]);
const scienceItemList = ref([]);
const loading1 = ref(false);
const loading2 = ref(false);

const studentLedItemList = computed(() =>
  scienceItemList.value.filter((item) => !item.ppName.includes("实训"))
);
const graduationTrainingList = computed(() =>
  scienceItemList.value.filter((item) => item.ppName.includes("实训"))
);

// 获取科研页展示的教师方向信息
const getTeasDirectionMessage = async () => {
  try {
    loading1.value = true;
    const res = await getLateDirections(4);
    console.log(res);
    const { code, data, msg } = res.data;
    if (code == SUCCESS) {
      teaDirectionList.value = data;
    } else {
      throw new Error("获取教师信息失败");
    }
    loading1.value = false;
  } catch (error) {
    ElMessage.error(error.message || "获取教师信息失败");
  }
};

// 获取科研类项目信息
const fetchScienceData = async () => {
  try {
    loading2.value = true;
    const res = await getProjectByKw({
      type: "类别",
      kw: "科研类",
      current: 1,
      size: 6,
    });
    const { code, data, msg } = res.data;
    if (code == SUCCESS) {
      scienceItemList.value = data.records;
    } else {
      throw new Error(msg);
    }
    loading2.value = false;
  } catch (error) {
    ElMessage.error(error.message || "获取项目数据失败");
  }
};

//更多相关信息跳转
const router = useRouter();
const changePage = () => {
  router.push({ path: "/innovation/teacher" });
};

onMounted(() => {
  // 获取科研页展示的教师方向信息
  getTeasDirectionMessage();
  // 获取科研类项目信息
  fetchScienceData();
});
</script>
<template>
  <div class="scienceBox">
    <div class="scienceTop">
      <h3 class="sTitle">教师科研</h3>
      <router-link to="/innovation/teacher" class="more"
        >>>更多信息</router-link
      >
    </div>
    <div v-loading="loading1" style="min-height: 180px">
      <div class="teacherItems">
        <div
          class="teacherItem"
          v-for="(item, index) in teaDirectionList"
          :key="index"
        >
          <div class="front">
            <h2>{{ item[0].sdName }}</h2>
            <span class="line"></span>
            <ul class="contact-info">
              <li
                class="directions"
                v-for="(diritem, dirindex) in item"
                :key="dirindex"
              >
                方向{{ dirindex + 1 }}：{{ diritem.sdDirectionName }}
              </li>
            </ul>
            <div class="back">
              <i
                class="iconfont icon-common_list_address"
                id="contact"
                :key="index"
                v-for="(item, index) in item[0].sdContact.split('|')"
                >&nbsp;联系方式：{{ item }}
              </i>
              <span class="selectMore" @click="changePage">更多相关信息</span>
            </div>
          </div>
        </div>
      </div>
    </div>

    <h3 class="sTitle">学生主导项目</h3>
    <div v-loading="loading2" style="min-height: 180px">
      <div
        class="studentItem"
        v-for="(stuLedItem, sciIndex) in studentLedItemList"
        :key="sciIndex"
      >
        <h3>{{ stuLedItem.ppName }}</h3>
        <div class="sIContent">
          <div class="sILeftBox">
            <span>简介：</span>
            <span>{{ stuLedItem.ppIntro }}</span>
          </div>
          <div class="sIRightBox">
            <span>本系适合对象：{{ stuLedItem.ppSuitableStudent }}</span>
            <span>指导老师：{{ stuLedItem.ppGuidanceTeacher }}</span>
            <span>参赛形式：{{ stuLedItem.ppCompetitionForm }}</span>
            <span>开始时间：{{ stuLedItem.ppApplyBegin }}</span>
            <span>周期：{{ stuLedItem.ppCircle }}</span>
          </div>
        </div>
      </div>
    </div>
    <h3 class="sTitle">毕业实训</h3>
    <div v-loading="loading2" style="min-height: 180px">
      <div
        class="studentItem"
        v-for="(graTrainItem, sciIndex) in graduationTrainingList"
        :key="sciIndex"
      >
        <h3>{{ graTrainItem.ppName }}</h3>
        <div class="sIContent">
          <div class="sILeftBox">
            <span>简介：</span>
            <span>{{ graTrainItem.ppIntro }}</span>
          </div>
          <div class="sIRightBox">
            <span>本系适合对象：{{ graTrainItem.ppSuitableStudent }}</span>
            <span>指导老师：{{ graTrainItem.ppGuidanceTeacher }}</span>
            <span>参赛形式：{{ graTrainItem.ppCompetitionForm }}</span>
            <span>开始时间：{{ graTrainItem.ppApplyBegin }}</span>
            <span>周期：{{ graTrainItem.ppCircle }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style scoped lang="less">
.scienceBox {
  margin-left: 32px;
  margin-right: 0px;
  width: 75%;
}

.scienceTop {
  display: flex;
  justify-content: space-between;
  width: 950px;
  align-items: center;
}

.more {
  text-decoration: none;
  color: grey;
  float: right;
}

/* 大标题前的小竖杠 */
.sTitle:before {
  content: "";
  background-color: #1e9ab5;
  width: 4px;
  height: 18px;
  position: absolute;
  left: -10px;
  margin-top: 5px;
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  border-radius: 3px;
}

.sTitle {
  font-size: 20px;
  margin: 20px 0px 10px 10px;
  position: relative;
}

/* 教师项目简介 */
.teacherItems {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 30px;
}

/* 教师简介小卡片 */
.teacherItem {
  width: 45%;
  height: 100%;
  margin-right: 30px;
  margin-bottom: 10px;

  .front {
    width: 85%;
    height: 180px;
    overflow: hidden;
    position: relative;
    background: aliceblue;
    padding: 40px;
    transform: perspective(600px);
    transition: all 0.5s ease;

    .contact-info {
      width: 90%;

      .directions {
        margin: 10px 0;
        display: flex;
        align-items: center;
        font-size: 16px;
      }
    }

    .line {
      background: #1a849c;
      width: 80px;
      height: 8px;
      display: inline-block;
      margin-bottom: 12px;
    }
  }

  .back {
    position: absolute;
    top: 0;
    width: 100%; /* back和front大小相同 */
    height: 100%; /* back和front大小相同 */
    visibility: hidden;
    transform: translateX(100%);
    background-color: rgba(26, 132, 156, 0.9);
    transition: all 0.5s ease;
    /* 布局 */
    display: flex;
    justify-content: center;
    flex-direction: column;
    padding-left: 10%;
    color: white;

    #contact {
      font-weight: bold;
      font-size: 18px;
    }

    .selectMore {
      font-weight: bold;
      font-size: 16px;
      margin-top: 5%;
      cursor: pointer;
    }
  }

  .front:hover .back {
    transform: translateX(0);
    visibility: visible;
  }
}

.front::before,
.front::after {
  content: "";
  position: absolute;
  right: 0;
}

.front::before {
  background: #1e9ab5;
  width: 80px;
  height: 120px;
  bottom: 0;
  clip-path: polygon(0 100%, 30% 0, 100% 100%);
}

.front::after {
  background: #1a849c;
  width: 100px;
  height: 100%;
  top: 0;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 80% 100%);
}

/* 科研类项目 */
.studentItem h3 {
  font-size: 18px;
  margin: 20px 0px 10px 10px;
}

.sIContent {
  display: flex;
  flex-direction: row;
}

.sILeftBox {
  width: 60%;
  border: 4px solid #1e9ab5;
  border-radius: 10px;
  padding: 20px;
}

.sIRightBox {
  width: 25%;
  padding: 20px;
  background-color: #1e9ab5;
  border-radius: 10px;
  margin-left: 10px;
  color: #ffffff;
  font-weight: bold;
}

.sILeftBox span,
.sIRightBox span {
  display: block;
  line-height: 25px;
}

.sILeftBox span:first-child {
  font-weight: bold;
}
</style>
